const findMembers = function (instance, { prefix, specifiedType, filter }) {
  // 递归函数
  function _find(instance) {
    //基线条件（跳出递归）
    if (instance.__proto__ === null) return []

    let names = Reflect.ownKeys(instance)
    names = names.filter((name) => {
      // 过滤掉不满足条件的属性或方法名
      return _shouldKeep(name)
    })

    return [...names, ..._find(instance.__proto__)]
  }

  function _shouldKeep(name) {
    if (filter && filter(name)) return true
    if (prefix && name.startsWith(prefix)) return true
    if (specifiedType && instance[name] instanceof specifiedType) return true
    return false
  }

  return _find(instance)
}

module.exports = {
  findMembers,
}
